//
//  FZ_BoFang_Two_TableViewCell.m
//  ProjectOfBStage
//
//  Created by dllo on 15/11/14.
//  Copyright © 2015年 cuixin. All rights reserved.
//

#import "FZ_BoFang_Two_TableViewCell_One.h"
#import <UIImageView+WebCache.h>
#import "BaseHeader.h"
//#import "POP.h"
//#import "POPSpringAnimation.h"
//#import "POPSpringAnimationInternal.h"
//#import "POPSpringSolver.h"

@interface FZ_BoFang_Two_TableViewCell_One ()
@property (nonatomic, retain) UITapGestureRecognizer *tapTouXiang;
@property (nonatomic,retain) UITapGestureRecognizer *tap;

@end
@implementation FZ_BoFang_Two_TableViewCell_One
- (void)dealloc
{
    [_JieShouModelF release];
    [_imageViewBack release];
    [_labelPlayTitle release];
    [_labelPlayState release];
    [_labelPlayerName release];
    [_tapTouXiang release];
    [_tap release];
    [_viewTouXiang release];
    [_imageViewTouXiang release];
    [_saveButton release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
//        self.contentView.userInteractionEnabled = YES;
        [self CreatTouXiang];
        
    }
    return self;
}

- (void)CreatTouXiang
{
    [self CreatViewBack];
    [self viewLayer];
    [self imageViewLayer];
    [self titleLabel];
}

- (void)CreatViewBack{
    self.imageViewBack = [[UIImageView alloc] init];
    self.imageViewBack.userInteractionEnabled = YES;
//    _imageViewBack.backgroundColor = [UIColor redColor];
    self.imageViewBack.image = [UIImage imageNamed:@"gobackbtn@2x.png"];

    [self.contentView addSubview:self.imageViewBack];
    [_imageViewBack release];
    self.tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.imageViewBack addGestureRecognizer:self.tap];

}

- (void)viewLayer
{
    [self.viewTouXiang removeFromSuperview];
    self.viewTouXiang = [[UIView alloc] init];
    self.viewTouXiang.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.viewTouXiang];
    [_viewTouXiang release];
    self.viewTouXiang.userInteractionEnabled = YES;
    self.viewTouXiang.layer.shadowOpacity = 1;
    self.viewTouXiang.layer.shadowColor = [UIColor yellowColor].CGColor;
    self.viewTouXiang.layer.shadowRadius = 10;
    self.viewTouXiang.layer.cornerRadius = 40;
    self.viewTouXiang.layer.borderColor = [UIColor clearColor].CGColor;
    self.viewTouXiang.layer.borderWidth = 2;
}

- (void)imageViewLayer
{
    [self.imageViewTouXiang removeFromSuperview];
    self.imageViewTouXiang = [[UIImageView alloc] init];
    self.imageViewTouXiang.layer.cornerRadius = 40;
    self.imageViewTouXiang.clipsToBounds = YES;
    self.imageViewTouXiang.layer.masksToBounds = YES;
    self.imageViewTouXiang.layer.backgroundColor = [UIColor whiteColor].CGColor;
    self.imageViewTouXiang.layer.borderWidth = 2;
    self.imageViewTouXiang.layer.borderColor = [UIColor whiteColor].CGColor;
    self.imageViewTouXiang.userInteractionEnabled = YES;
    [self.viewTouXiang addSubview:self.imageViewTouXiang];
    [_imageViewTouXiang release];
//
//    CABasicAnimation *basicanimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
//    [basicanimation setDuration:3];
//    [basicanimation setRepeatCount:NSIntegerMax];
//    basicanimation.fromValue = [NSNumber numberWithInt:0];
//    basicanimation.toValue = [NSNumber numberWithFloat:M_PI * 2];
//    [self.imageViewTouXiang.layer addAnimation:basicanimation forKey:@"transform"];
//    basicanimation.autoreverses = YES;
    [self addSubview:self.viewTouXiang];
}

- (void)titleLabel{

    self.labelPlayState = [[UILabel alloc] init];
//    self.labelPlayState.backgroundColor = [UIColor blueColor];
    [self.labelPlayState setTextColor:[UIColor whiteColor]];
    self.labelPlayState.text = @"正在播放";
//    NSLog(@"11111");
    self.labelPlayState.font = [UIFont systemFontOfSize:15];
    self.labelPlayState.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.labelPlayState];
    [_labelPlayState release];
    
    self.labelPlayTitle = [[UILabel alloc] init];
    self.labelPlayTitle.textAlignment = NSTextAlignmentLeft;
    [self.labelPlayTitle setTextColor:[UIColor whiteColor]];
    self.labelPlayTitle.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.labelPlayTitle];
    [_labelPlayTitle release];
//    POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionX];
//    anim.toValue = @(185);
//    anim.springSpeed = 4.0;
//    anim.springBounciness = 15.0;
//    anim.beginTime = CACurrentMediaTime() + 1;
//    [self.labelPlayTitle pop_addAnimation:anim forKey:@"labelPlayTitle"];
    
    
    //收藏按钮初始化
    self.saveButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [self.saveButton setBackgroundImage:[UIImage imageNamed:@"likeWhite.png"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.saveButton];
    
    
    self.labelPlayerName = [[UILabel alloc] init];
    self.labelPlayerName.textAlignment = NSTextAlignmentLeft;
    [self.labelPlayerName setTextColor:[UIColor lightGrayColor]];
//    [_labelPlayerName setBackgroundColor:[UIColor yellowColor]];

    self.labelPlayerName.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.labelPlayerName];
    [_labelPlayerName release];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.imageViewBack.frame = CGRectMake(20.f, 15.f, 30.f, 30.f);
    self.viewTouXiang.frame = CGRectMake(40.f, 100.f ,80.f , 80.f );
    self.imageViewTouXiang.frame = CGRectMake(0, 0, 80.f , 80.f );
    self.labelPlayState.frame = CGRectMake(150.f, self.imageViewBack.frame.origin.y + 5.f, 75.f, 20.f);
    //收藏按钮的坐标
    self.saveButton.frame = CGRectMake(self.frame.size.width - 40.f, self.labelPlayState.frame.origin.y, 20, 20);
    self.labelPlayTitle.frame = CGRectMake(self.viewTouXiang.frame.origin.x + 20.f + self.viewTouXiang.frame.size.width, self.viewTouXiang.frame.origin.y + 4, 160.f, 20.f);
    self.labelPlayerName.frame = CGRectMake(self.labelPlayTitle.frame.origin.x, self.labelPlayTitle.frame.origin.y + 5 + self.labelPlayTitle.frame.size.height, 80.f, 20.f);

}

- (void)setJieShouModelF:(FZ_RootModelR *)JieShouModelF{
    if (_JieShouModelF != JieShouModelF) {
        [_JieShouModelF release];
        _JieShouModelF = [JieShouModelF retain];
    }
    if (JieShouModelF.name != nil) {
        self.labelPlayTitle.text = JieShouModelF.name;
        self.labelPlayerName.text = [JieShouModelF.user objectForKey:@"name"];
        [self.imageViewTouXiang sd_setImageWithURL:[NSURL URLWithString:JieShouModelF.pic] placeholderImage:WAIT_PICTURE];
    }else{
        self.labelPlayTitle.text = JieShouModelF.name;
        self.labelPlayerName.text = [JieShouModelF.user objectForKey:@"name"];
        [self.imageViewTouXiang sd_setImageWithURL:[NSURL URLWithString:self.pic] placeholderImage:WAIT_PICTURE];
    }
    
}
-(void)setDetailModel:(CXFirstDetailModel *)detailModel{
    if (_detailModel != detailModel) {
        [_detailModel release];
        _detailModel = [detailModel retain];
    }
    self.labelPlayTitle.text = detailModel.name; 
//    self.labelPlayerName.text = [detailModel.user objectForKey:@"name"];
    [self.imageViewTouXiang sd_setImageWithURL:[NSURL URLWithString:detailModel.pic] placeholderImage:WAIT_PICTURE];
}
- (void)tapAction:(UITapGestureRecognizer *)sender{
    [self.delegateBack ImageViewBack];
}

- (void)tapTouXiangF:(UITapGestureRecognizer *)sender{
    CGPoint touchPoint = [sender locationInView:self.imageViewTouXiang];
    if ([self.imageViewTouXiang.layer.presentationLayer hitTest:touchPoint]) {
        [self.delegateDongHua DongHuaDelegate:nil and:self.JieShouModelF];
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
